//
//  83. 删除排序链表中的重复元素.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/9/5.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation
class Solution83 {
    // 删除链表中的重复元素
    // 只要与前面一个相同删掉即可
    func deleteDuplicates(_ head: ListNode?) -> ListNode? {
        var cur = head
        while cur?.next != nil {
            if cur?.val != cur?.next?.val {
                cur = cur?.next
            } else {
                cur?.next = cur?.next?.next
            }
        }
        return head
    }
    static func test() {
        let solution = Solution83()
        solution.deleteDuplicates(nil)
    }
    
}
